<?php
// +----------------------------------------------------------------------
// | Ceeen Wise System
// +----------------------------------------------------------------------
// | Copyright (c) 2007-2017 http://www.sharpwe.com All rights reserved.
// +----------------------------------------------------------------------
// | Date: 2019/9/20 Time: 20:26
// +----------------------------------------------------------------------
// | Author: fely <fely@fely.cc> 
// +----------------------------------------------------------------------

namespace common\traits;


use common\ApiErrorDic;

trait ApiJump
{

    /**
     * 正确信息
     *
     * @param null $data
     * @param $msg
     * @param $code
     * @return mixed
     */
    public function success($data = null, $msg = ApiErrorDic::SUCCESS['message'], $code = ApiErrorDic::SUCCESS['code'])
    {
        if (is_object($data)) {
            $data = $data->toArray();
        }
        return app('json')->success($data, $code, $msg);
    }

    /**
     * 错误信息
     *
     * @param $msg
     * @param $code
     * @param null $data
     * @return mixed
     */
    public function error($code = ApiErrorDic::UNKNOWN_ERROR['code'], $msg = ApiErrorDic::UNKNOWN_ERROR['message'], $data = null)
    {
        return app('json')->fail($data, $code, $msg);
    }
}